package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品分类管理类")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("新增菜品分类")
    @PostMapping
    public Result saveCategory(@RequestBody CategoryDTO dto) {
        categoryService.saveCategory(dto);
        return Result.success();
    }

    @ApiOperation("按条件查找菜品分类")
    @GetMapping("/page")
    public Result getAllCategory(CategoryPageQueryDTO dto) {

        PageResult pageResult = categoryService.getAllCategory(dto);

        return Result.success(pageResult);
    }

    @ApiOperation("根据id删除菜品分类")
    @DeleteMapping
    public Result deleteCategory(Long id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }

    @ApiOperation("修改菜品分类信息")
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO dto) {
        categoryService.updateCategory(dto);
        return Result.success();
    }

    @ApiOperation("修改菜品分类状态")
    @PostMapping("/status/{status}")
    public Result updateCategoryStatus(@PathVariable Integer status,Long id) {
        categoryService.updateCategoryStatus(status,id);
        return Result.success();
    }

    @ApiOperation("按分类类型查找")
    @GetMapping("/list")
    public Result getCategoryByType(Integer type) {
        List<Category> categoryList = categoryService.getCategoryByType(type);
        return Result.success(categoryList);
    }
}
